<template>
  <el-select @change="changeChannel" clearable :value="value" placeholder="请选择">
    <el-option v-for="item in channelOptions" :label="item.name" :value="item.id" :key="item.id"></el-option>
  </el-select>
</template>

<script>
export default {
  name: "my-channel",
  props: ['value'],
  data() {
    return {
      channelOptions: []
    };
  },
  created() {
    this.getChannelOptions();
  },
  methods: {
    changeChannel(channelId) {
        if (channelId === '') channelId = null 
        this.$emit('input', channelId)
    },
    async getChannelOptions() {
      const {
        data: { data }
      } = await this.$http.get("/channels");
      this.channelOptions = data.channels;
    }
  }
};
</script>